import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        char[][] grid = new char[n][m];

        int result = 0;

        for (int i = 0; i < n; i++) {
            String line = sc.next();
            for (int j = 0; j < m; j++) {
                grid[i][j] = line.charAt(j);
            }
        }
        List<Character> t=new ArrayList<>();
        t.add('1'); t.add('2'); t.add('3');
        t.add('4'); t.add('5'); t.add('6');
        t.add('7'); t.add('8'); t.add('9');

        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                char c = grid[i][j];
                if (t.contains(c)){
                    result++;
                    helper(grid,i,j);
                }
            }
        }

        System.out.println(result);

    }

    private static void helper(char[][] grid, int i, int j) {

        if (i<0 ||j<0||i==grid.length||j==grid[0].length||grid[i][j]=='0'||grid[i][j]=='A'){
            return;
        }

        grid[i][j]='A';
        helper(grid,i-1,j);
        helper(grid,i+1,j);
        helper(grid,i,j-1);
        helper(grid,i,j+1);
    }
}